#include <jni.h>
#include <string>
#include <android/log.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <fstream>
#include <unistd.h>

static jint fd;
extern "C" JNIEXPORT jstring JNICALL
Java_com_example_myapplication_MainActivity_stringFromJNI(
        JNIEnv *env,
        jobject /* this */) {
    std::string hello = "Hello from C++";
    return env->NewStringUTF(hello.c_str());
}
extern "C"
JNIEXPORT jint JNICALL
Java_com_example_myapplication_HardControl_ledCtrl(JNIEnv *env, jclass type, jint which,
                                                   jint status) {

    int ret = ioctl(fd, status, which);
    __android_log_print(ANDROID_LOG_DEBUG,"LED Demo","native contorl %d", ret);
    return ret;

}extern "C"
JNIEXPORT jint JNICALL
Java_com_example_myapplication_HardControl_ledOpen(JNIEnv *env, jclass type) {

    fd = open("/dev/leds",O_RDWR);
    __android_log_print(ANDROID_LOG_DEBUG,"LED Demo","native open %d", fd);
    if(fd >= 0)
        return 0;
    else
        return -1;

}extern "C"
JNIEXPORT void JNICALL
Java_com_example_myapplication_HardControl_ledClose(JNIEnv *env, jclass type) {

    __android_log_print(ANDROID_LOG_DEBUG,"LED Demo","native close");
    close(fd);

}